package com.ajl.wx.module.wechat.service.impl;

import com.ajl.wx.beans.po.WechatUserPO;
import com.ajl.wx.config.UrlConfig;
import com.ajl.wx.config.WebApplicationProperties;
import com.ajl.wx.module.wechat.mapper.TbWechatUserMapper;
import com.ajl.wx.module.wechat.service.ITbWechatUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HouXinLin
 * @since 2020-09-24
 */
@Service
public class TbWechatUserServiceImpl extends ServiceImpl<TbWechatUserMapper, WechatUserPO> implements ITbWechatUserService {
    @Autowired
    RestTemplate restTemplate;

    @Autowired
    WebApplicationProperties webappProperties;

    @Override
    public String code2Session(String jsCode) {
        ResponseEntity<Map> forEntity = restTemplate.getForEntity(UrlConfig.buildCode2Session(webappProperties, jsCode), Map.class);
        return (String) forEntity.getBody().get("openid");
    }
}
